package com.ruoyi.contract.tools;

import com.ruoyi.common.utils.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: Smart-contract-management-system-replica-system
 * @description: 发票编码生成
 * @author: coderChen
 * @create: 2024-10-22 16:04
 **/

public class InvoiceCode {
    // 定义日期格式
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");

    public static String getInvoiceCode(String companyName, String type) {
        if (companyName == null || type == null) {
            throw new IllegalArgumentException("Company name and type cannot be null.");
        }

        // 获取公司名称的拼音首字母
        String companyNamePingying = ChineseUtil.getFirstLetter(companyName);
        // 根据发票类型生成发票编码
        String invoiceType = getInvoiceType(type);
        //返回编码
        return companyNamePingying + invoiceType + InvoiceCode.getNowDate();
    }

    private static String getInvoiceType(String type) {
        switch (type) {
            case "0":
                return "XX";
            default:
                return "JX";
        }
    }
    // 获取当前时间并转换为字符串
    private static String getNowDate() {
        return DATE_FORMAT.format(new Date());
    }
}
